<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="内容:" prop="content">
                    <el-input v-model="form.content" placeholder="请输入内容" :rows="4" type="textarea" />
                </el-form-item>
                <el-form-item label="图片:" prop="pic_urls">
                    <ImageUpload v-model="form.pic_urls" :limit="10" />
                </el-form-item>
                <el-row>
                    <el-col :span="12"  v-if="disabled">
                        <el-form-item label="所属用户:" prop="user_id">
                            <SelectPage v-model="form.user_id" :url="'/admin/user/selectPage'"
                                        show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="查看数:" prop="view_num">
                            <el-input-number v-model="form.view_num" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="分享数:" prop="share_num">
                            <el-input-number v-model="form.share_num" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="地址:" prop="address">
                            <el-input v-model="form.address" placeholder="请输入地址" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="点赞数:" prop="zan_num">
                            <el-input-number v-model="form.zan_num" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="收藏数:" prop="collect_num">
                            <el-input-number v-model="form.collect_num" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="评论数:" prop="comment_num">
                            <el-input-number v-model="form.comment_num" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="排序:" prop="sortweight">
                            <el-input-number v-model="form.sortweight" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="话题:" prop="tag_datas">
                            <el-input v-model="form.tag_datas" placeholder="请输入话题" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="disabled">
                        <el-form-item label="宝宝周数:" prop="baby_week">
                            <el-input-number v-model="form.baby_week" :step="1" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                user_id: [{ required: true, message: "请输入所属用户", trigger: "blur" }],
                data_type: [{ required: true, message: "请输入内容类型", trigger: "blur" }],
                content: [{ required: true, message: "请输入内容", trigger: "blur" }],
                status: [{ required: true, message: "请输入状态", trigger: "blur" }],
                address: [{ required: true, message: "请输入地址", trigger: "blur" }],
                // tag_datas: [{ required: true, message: "请输入话题", trigger: "blur" }],
            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            data_type:[
               { label: "图文", value: 1 },
               { label: "视频", value: 2 },
            ],
            status:[
               { label: "发布中", value: 1 },
               { label: "草稿", value: 2 },
               { label: "审核中", value: 3 },
               { label: "已删除", value: 8 },
            ],

        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
